﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AteneoLibri
{
    public partial class About : System.Web.UI.Page
    {
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (User.Identity.IsAuthenticated)
            {
                if (User.Identity.Name.Equals(System.Configuration.ConfigurationManager.AppSettings["AdminName"]))
                {
                    Page.MasterPageFile = "~/BackEnd/BackEndMasterPage.Master";
                }
                else
                {
                    Page.MasterPageFile = "~/Account/NewAccountMasterPage.Master";
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void btnRequest_Click(object sender, EventArgs e)
        {
            recaptcha.Validate();
            if (recaptcha.IsValid)
            {
                if (Page.IsValid)
                {
                    string subject = txtTitle.Text.Trim();
                    string body = txtNote.Text.Trim();
                    string email = txtEmail.Text.Trim();

                    Utility.Mail.MailSender mailSender = new Utility.Mail.MailSender();
                    try
                    {
                        mailSender.SendMail("info@ateneolibri.it", "Segnalazione: " + subject, body + "<br /><br /><a href\"mailto:" + email + "\">" + email + "</a>", true);
                        pnlRequestSuccessfullyCompleted.Visible = true;

                        pnlRequest.Visible = false;
                        pnlError.Visible = false;
                    }
                    catch (Exception ex)
                    {
                        pnlError.Visible = true;
                        lblError.Text = ex.Message;
                    }
                    
                }
            }
            else
            {
                pnlError.Visible = true;
                lblError.Text = recaptcha.ErrorMessage;
            }
        }

        protected void btnAnnulla_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Default.aspx");
        }
    }
}
